package com.johanChan.service;

import com.johanChan.entity.User;
import com.johanChan.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    UserMapper userMapper;

    public User Sel(int id){
        return userMapper.Sel(id);
    }

    public boolean login(String userName, String passWord) {
        boolean bool = false;
        User user = userMapper.login(userName);
        if (null != user && null != user.getPassword()){
            String dbPassword = user.getPassword().substring(0, 1) + user.getPassword().substring(6);
            String reqPassword = passWord.substring(0, 1) + passWord.substring(6);
            if ( dbPassword.equals(reqPassword)){
                bool = true;
            }
        }
        return bool;
    }

    public int register(User user) {
        return userMapper.register(user);
    }
}
